<?php
class SalasUsersController extends AppController {

	var $name = 'SalasUsers';
	var $helpers = array('Html', 'Form','Javascript','Ajax');
	var $components = array('RequestHandler');
	/*function index() {
		$this->SalasUser->recursive = 0;
		$this->set('salasUsers', $this->paginate());
	}*/
	
	function beforeFilter() {
		parent::beforeFilter(); 
		$this->Auth->allowedActions = array('index');
	}
/*Obtengo los usuarios que en la Sala
	Parametros:
$salaId: identificador de la sala
*/
	function index($salaId = null){
		$this->set('salasUsers', $this->SalasUser->find('all', array('SalasUser.sala_id ' => $salaId)));
		if($this->params['isAjax']){
			$this->render('usuariosEnSala');
		}
	}
	
	function view($id = null) {
		if (!$id) {
			$this->flash(__('Invalid SalasUser', true), array('action'=>'index'));
		}
		$this->set('salasUser', $this->SalasUser->read(null, $id));
	}

	function add() {
		
		//$this->data = $data;
		
		if (!empty($this->data)) {
	
			$this->SalasUser->create();
			if ($this->SalasUser->save($this->data)) {
				$this->flash(__('SalasUser saved.', true), array('action'=>'index'));
				return true;
			} else {
				return false;
			}
		}
		//$users = $this->SalasUser->User->find('list');
		//$salas = $this->SalasUser->Sala->find('list');
		//$this->set(compact('users', 'salas'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->flash(__('Invalid SalasUser', true), array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->SalasUser->save($this->data)) {
				$this->flash(__('The SalasUser has been saved.', true), array('action'=>'index'));
			} else {
			}
		}
		if (empty($this->data)) {
			$this->data = $this->SalasUser->read(null, $id);
		}
		$users = $this->SalasUser->User->find('list');
		$salas = $this->SalasUser->Sala->find('list');
		$this->set(compact('users','salas'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->flash(__('Invalid SalasUser', true), array('action'=>'index'));
		}
		if ($this->SalasUser->del($id)) {
			$this->flash(__('SalasUser deleted', true), array('action'=>'index'));
		}
	}
	

	

}
?>